﻿@{
    ViewBag.Title = "TestLibExamView";
    Layout = "~/Views/Shared/_GridCommonLayout.cshtml";
}

<style type="text/css">
    .red {
        color:red;
    }
    .green {
        color:green;
    }
</style>
<!--begin grid code-->
<!--获取当前课程的ID-->
<input id="HiddenCourseID" type="hidden" value="@ViewBag.CourseID">


<section id="widget-grid" class="">
    <div class="row">




        <!--Operation-->
        <div class="heading-buttons">


            <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
                <h1 class="page-title txt-color-blueDark"><i class="fa fa-pencil-square-o  "></i>
                    试卷库管理
			
                </h1>
            </div>
            <div class="buttons pull-right">

                <button type="button" class="btn btn-success btn-labeled " onclick="location.href='/TeacherManger/PaperCreateView?CourseID=@ViewBag.CourseID'">
                    <span class="btn-label"><i class="glyphicon glyphicon-plus"></i>
                    </span>新增试卷</button>

                <button type="button" class="btn btn-primary btn-labeled "
                    data-bind="click: $root.onDataDeleting">
                    <span class="btn-label"><i class="glyphicon glyphicon-remove"></i>
                    </span>批量删除</button>

            </div>
            <div style="clear: both;">
            </div>
        </div>
        <!--/Operation-->


        <!--Search-->
        <div class="filter-bar">
            <form id="formSearch">
                <div class="lbl glyphicons search" style="cursor: pointer;" data-bind="click: $root.search">
                    <i></i>筛选
                </div>

                <div>
                    <label>试卷名称：</label><div class='input-append'>
                        <input id='txtbSrSTestName' name='txtbSrSTestName' type='text' placeholder='试卷名' class='input-mini' style='width: 120px;' />
                     <input id='txtbSrICourseId' name='txtbSrICourseId' type='hidden' value="@ViewBag.CourseID"/>
                    </div>
                </div>
                <div>
                    <label>考核方式：</label>
                    <div class='input-append'>
                        <select name="txtbSrITestType" id="txtbSrITestType" class='input-mini' style='width: 120px;'>

                            <option value="">请选考核方式</option>
                            <option value="0">---开卷---</option>
                            <option value="1">---闭卷---</option>
                        </select>
                    </div>
                </div>
                <div>
                    <label>考试类型：</label>
                    <div class='input-append'>
                        <select name="txtbSrIKsType" id="txtbSrIKsType" class='input-mini' style='width: 120px;'>
                            <option value="">请选考试方式</option>
                            <option value="1">---线上---</option>
                            <option value="0">---线下---</option>

                        </select>
                    </div>

                </div>
                <div class="clearfix">
                </div>
            </form>
        </div>
        <!--/search-->



        <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12 sortable-grid ui-sortable">
            <div id="wid-id-0" class="jarviswidget jarviswidget-color-darken jarviswidget-sortable" data-widget-editbutton="false">
                <header>
                    <span class="widget-icon"><i class="fa fa-table"></i></span>
                    <h2>试卷库</h2>
                </header>
                <div style="margin-top: 35px;">
                    <div class="jarviswidget-editbox"></div>
                    <div class="widget-body no-padding">
                        <div role="grid" id="providerGrid" class="dataTables_wrapper form-inline">
                            <div class="table-responsive">

                                <div class="dt-wrapper" style="overflow-y: auto;">
                                    <table class="table table-striped table-bordered table-hover checkboxs">
                                        <!--table head-->
                                        <thead>
                                            <tr>
                                                <th style="width: 1%">
                                                    <input type="checkbox" value="0" />
                                                </th>
                                                <!-- ko foreach: headers -->
                                                <th class="left ">
                                                    <a href="#" data-bind="text: displayText@*, click: $root.sort*@" style="color: black"></a>
                                                    <i class="icon-circle-arrow-up" data-bind="    visible: value == $root.orderBy() && $root.isAsc()"></i>
                                                    <i class="icon-circle-arrow-down" data-bind="    visible: value == $root.orderBy() && !$root.isAsc()"></i>
                                                </th>
                                                <!-- /ko -->
                                                <th class="center" style="width: 60px">导出Word
                                                </th>
                                                <th class="center" style="width: 60px">预览
                                                </th>
                                            </tr>
                                        </thead>
                                        <!--/table head-->
                                        <!--table body(Provider list)-->
                                        <tbody data-bind="foreach: recordSet">
                                            <tr class="selectable" onclick="">
                                                <td class="center">
                                                    <input type="checkbox" name="userSelector" data-bind="value: Id" />
                                                    <input type="hidden" data-bind="value: Id, attr: { id: Id }" />
                                                </td>

                                                <td class='left'><strong data-bind='text: STestName'></strong></td>

                                                <td class='left'><strong data-bind='text: STeaName'></strong></td>


                                                <td class='left'><strong data-bind='text: ITotal'></strong></td>

                                                <td class='left'><strong data-bind='text: IHardlevel'></strong></td>
                                                <td class='left'><strong data-bind='text: IOverTime'></strong></td>
                                                <td class='left'><strong data-bind='text: $root.formatKsType(IKsType)'></strong></td>
                                                <td class='left'><strong data-bind='text:$root.formatTestType(ITestType)'></strong></td>
                                                <td class='left'><strong data-bind='css:$root.fontColor(IIsOk),text: $root.formatIsOk(IIsOk)'></strong></td>


                                                <td class="center">
                                                    <a href="#" class="glyphicon glyphicon-export" data-bind="click:$root.exportWord">
                                                        <i></i></a>
                                                </td>

                                                <td class="center">
                                                    <a href="#" class="btn-action glyphicons pencil " data-bind="click:$root.PaperView">
                                                        <i></i></a>
                                                </td>
                                            </tr>
                                        </tbody>
                                        <!--/table body( Provider list)-->

                                    </table>

                                </div>



                                <!-- 分页 -->
                                <ul class="pagination pagination-alt">
                                    <li>
                                        <a data-bind="click: firstPage"><i class="fa fa-fast-backward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: prevPage"><i class="fa  fa-backward  "></i></a>
                                    </li>
                                    <li>
                                        <a>
                                            <input id="toPage" type="text" data-bind="value: pageIndex, event: { change: $root.changePageIndex }" style="width: 25px;" />
                                            /共<span data-bind="html: totalPages"></span>页 
                                        </a>
                                    </li>
                                    <li>
                                        <a data-bind="click: nextPage"><i class="fa fa-forward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: lastPage"><i class="fa fa-fast-forward "></i></a>
                                    </li>
                                </ul>

                                <div class="dt-top-row total  ">
                                    当前记录共：<span data-bind="html: totalCount"></span>条
                                </div>
                                <!--end 分页-->
                            </div>

                            <!-- /分页 -->


                        </div>

                        <!-- /分页 -->




                    </div>
                </div>

            </div>




        </article>

    </div>
    <!--end row-->
</section>




<script type="text/javascript">

    var gdViewModel;
    $(function () {
        $._messengerDefaults = {
            extraClasses: 'messenger-fixed messenger-theme-future messenger-on-bottom messenger-on-right'
        }; //默认提示位置;


        var options = {

            dialogId: "TestLibPaperMessageModal", //添加对话框

            pageSize: 20, //分页大小
            hidId: $("#txtbID"),
            SaveUpdateBtn: $("#btnSaveOrUpdateModel"),
            frmElement: $("#formTestLibPaper"),

            //节点数据
            NodeValue: ko.observable({

                Id: 0,
                STestName: '',
                ICourseId: 0,
                SCouseCode: '',
                ITeaId: 0,
                STeaCode: '',
                ITermId: 0,
                DCreateTime: new Date(),
                SIp: '',
                IOverTime: 0,
                ITestType: 0,
                ITotal: 0,
                IIsOk: 0,
                DTestTime: new Date(),
                IDiff: 0,
                IHardlevel: 0,
                IKsType: 0,
                STeaName: '',


            }),


            //用户列表Grid头部列名称
            headers: [


 { displayText: '试卷名称', value: 'STestName', width: 'auto' },
 { displayText: '发布教师', value: 'STeaName', width: 'auto' },


 { displayText: '总分', value: 'ITotal', width: 'auto' },

 { displayText: '难易度', value: 'IHardlevel', width: 'auto' },
 { displayText: '完成时间', value: 'IOverTime', width: 'auto' },
 { displayText: '考试类型', value: 'IKsType', width: 'auto' },
  { displayText: '考核方式', value: 'ITestType', width: 'auto' },
 { displayText: '审核状态', value: 'IIsOk', width: 'auto' }

            ],

            //默认的排序方式
            defaultOrderBy: "Id",
            //用户查询URL
            dataQueryUrlAccessor: function () {
                return "/api/TestLibPaperExt/Search/";
            },

            //添加用户URL
            dataAddUrlAccessor: function () { return "/api/TestLibPaper/Post"; },
            dataUpdateAccessor: function (key) { return "/api/TestLibPaper/Put/" + key; },
            dataNodeSelect: function (id) {
                return "/api/TestLibPaper/get/" + id;
            },

            dataDeleteAccessor: function (data) {
                var userIDs = "";
                var check = $("input:checked");  //得到所有被选中的checkbox
                check.each(function (i) {        //循环拼装被选中项的值
                    userIDs = userIDs + ',' + $(this).val();
                });
                //清除多余的分割号
                userIDs = dropRsplit(userIDs, ",");
                if (userIDs != "") {
                    return appendQueryString("/api/TestLibPaperExt/DeletePaper", { ids: userIDs });
                } else
                    return "";

            }
			, initEd: function () {
			    //gird初始化的后置事件 信息

			}

        };

        gdViewModel = new gridViewModel(options);

        //导出试卷
        gdViewModel.exportWord = function (data) {
            window.location.href = "/api/TestLibPaperExt/ExportWord?paperId=" + data.Id;
        }

        //转换考核方式为对应的字符串
        gdViewModel.formatTestType = ko.observable();
        gdViewModel.formatTestType = function (ITestType) {
            if (ITestType == 1) {
                return "闭卷";
            }
            else {
                return "开卷";
            }
        }

        //转换考试类型为对应的字符串
        gdViewModel.formatKsType = ko.observable();
        gdViewModel.formatKsType = function (IKsType) {
            if (IKsType == 1) {
                return "线上";
            }
            else {
                return "线下";
            }
        }
        //是否通过，通过为绿，未通过红
        gdViewModel.fontColor = function (data) {
            if (data == 0)
                return "red";
            else
                return "green";
        }
        //转换审核状态为对应的字符串
        gdViewModel.formatIsOk = ko.observable();
        gdViewModel.formatIsOk = function (IIsOk) {
            if (IIsOk == 0) {
                return "未通过";
            }
            else if (IIsOk == 5) {
                return "审核中";
            }
            else {
                return "通过";
            }
        }

        gdViewModel.PaperView = function (data) {
            var url = "/TeacherManger/TestPaperPreview?PaperID=" + data.Id;
            window.open(url, "_blank");
           // window.location.href = "/TeacherManger/TestPaperPreview?PaperID=" + data.Id;
        }

        gdViewModel.init();
        ko.applyBindings(gdViewModel);


        options.frmElement.validate({
            rules: {


                txtbId: { required: true, digits: true }, txtbSTestName: { maxlength: 50 }, txtbICourseId: { digits: true }, txtbSCouseCode: { maxlength: 50 }, txtbITeaId: { digits: true }, txtbSTeaCode: { maxlength: 50 }, txtbITermId: { digits: true }, txtbDCreateTime: { date: true }, txtbSIp: { maxlength: 50 }, txtbIOverTime: { digits: true }, txtbITestType: { digits: true }, txtbITotal: { digits: true }, txtbIIsOk: { digits: true }, txtbDTestTime: { date: true }, txtbIDiff: { digits: true }, txtbIHardlevel: { digits: true }, txtbIKsType: { digits: true }



            },
            messages: {


                txtbId: { required: '必填项', digits: '必须是整数' }, txtbSTestName: { maxlength: '最大长度为100' }, txtbICourseId: { digits: '必须是整数' }, txtbSCouseCode: { maxlength: '最大长度为10' }, txtbITeaId: { digits: '必须是整数' }, txtbSTeaCode: { maxlength: '最大长度为10' }, txtbITermId: { digits: '必须是整数' }, txtbDCreateTime: { date: '必须是日期格式，例如：2013/01/01' }, txtbSIp: { maxlength: '最大长度为25' }, txtbIOverTime: { digits: '必须是整数' }, txtbITestType: { digits: '必须是整数' }, txtbITotal: { digits: '必须是整数' }, txtbIIsOk: { digits: '必须是整数' }, txtbDTestTime: { date: '必须是日期格式，例如：2013/01/01' }, txtbIDiff: { digits: '必须是整数' }, txtbIHardlevel: { digits: '必须是整数' }, txtbIKsType: { digits: '必须是整数' }

            }
        });


    });

</script>






<!--/end grid code-->

